import requests
from requests_toolbelt import sessions
from requests.adapters import HTTPAdapter

###############
#设置base_url
###############
session = sessions.BaseUrlSession(base_url="http://127.0.0.1:8000")
session.get("/userlist")



###############
#建立全局等待时间
###############
class TimeoutHTTPAdapter(HTTPAdapter):
    def __init__(self, *args, **kwargs):
        self.timeout = 10
        if "timeout" in kwargs:
            self.timeout = kwargs["timeout"]
        super().__init__(*args, **kwargs)

    def send(self, request, **kwargs):
        kwargs['timeout'] = self.timeout
        return super().send(request, **kwargs)
    
session =requests.Session()
adapter = TimeoutHTTPAdapter(timeout=10)
session.mount("http://",adapter)
session.mount("https://",adapter)

#使用全局等待
response = session.get("/userlist")
#不使用全局等待
response = session.get("/userlist",timeout=10)


###############
# 全局变量管理器
# 可以在全局变量管理器中设置全局变量，在测试用例中可以直接使用全局变量
# 见glo.py
###############

